package com.cskaoyan.exception.wx_storage;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.admin.Admin;
import com.cskaoyan.bean.user.User;
import com.cskaoyan.bean.wx_resp.WxRespVo;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-23
 */
@RestControllerAdvice
public class StorageExceptionControllerAdvice {

    @ExceptionHandler(FileIllegalArgumentException.class)
    public Object fileIllegalArgumentException(FileIllegalArgumentException ex) {
        Object principal = SecurityUtils
                .getSubject()
                .getPrincipals()
                .getPrimaryPrincipal();
        if (principal instanceof Admin) {
            return BaseRespVo.error(ex.getMessage());
        } else if (principal instanceof User) {
            return WxRespVo.error(ex.getMessage());
        }
        return null;
    }
}
